home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / conqsrc.lha / Conquest / src / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-03  |  1.9 KB  |  117 lines

  1. /* Input.c: Inputting routines */
  2. #include <stdio.h>
  3. #include "defs.h"
  4. #include "structs.h"
  5. #include "vars.h"
  6. #include "protos.h"
  7.  
  8. char get_char()
  9. {
  10.   char result;
  11.  
  12.   fread(&result, 1, 1, raw_fd);
  13.   if (result == 0x0d)
  14.     result = '\n';
  15.  
  16.   printf("%c", toupper(result));
  17.  
  18.   return(toupper(result));
  19. }
  20.  
  21. void get_line(char *iline)
  22. {
  23.   char ch;
  24.   int ind;
  25.   
  26.   ind=0;
  27.   do
  28.   {
  29.     ch = get_char();
  30.     if (ch == '\b') 
  31.     { /*backspace*/
  32.       if (ind > 0)
  33.       {
  34.     putchar(' ');
  35.     putchar('\b');
  36.     /* Erase old char */
  37.     putchar(' ');
  38.     putchar('\b');
  39.     ind = ind - 1;
  40.       }
  41.       else
  42.     move(1,0);
  43.     } 
  44.     else if (ch != '\n') 
  45.     {
  46.       iline[ind] = ch;
  47.       ind = ind + 1;
  48.     }
  49.   }
  50.   while (ind < 25 && ch != '\n');
  51.  
  52.   iline[ind] = 0;
  53. }
  54.  
  55. float dist(int star1, int star2)
  56. {
  57.   register int square;
  58.  
  59.   square = 
  60.     abs(stars[star1].x-stars[star2].x)*abs(stars[star1].x-stars[star2].x)+
  61.       abs(stars[star1].y-stars[star2].y)*abs(stars[star1].y-stars[star2].y);
  62.  
  63.   return(sqrt((float)square));
  64. }
  65.  
  66. int get_stars(int s_star, float slist[])
  67. {
  68.   int starnum, count;
  69.   
  70.   count = 0;
  71.   for (starnum = 1 ; starnum <= nstars; starnum++) 
  72.   {
  73.     /* Fudge a bit to avoid doing long squareroots */
  74.     if (range[0] >= (slist[starnum] = dist(s_star,starnum)))
  75.       count++;
  76.     else
  77.       slist[starnum] = 0;
  78.   }
  79.   return(count);
  80. }
  81.  
  82. char get_token(char *line, int *Value)
  83. {
  84.   int index, value; 
  85.   char token;
  86.  
  87.   index = 0;
  88.   value = 0;
  89.   token = ' ';
  90.   while (isspace(line[index])) index++;
  91.  
  92.   if (line[index])
  93.   {
  94.     if ((line[index] < '0') || (line[index] > '9'))
  95.       value = 1;
  96.     else 
  97.     {
  98.       while ((line[index] >= '0') && (line[index] <= '9')) 
  99.       {
  100.     value = 10*value + line[index] - '0';
  101.     index++;
  102.       }
  103.     }
  104.     token = line[index];
  105.     index++;
  106.   }
  107.  
  108.   while (isspace(line[index])) index++;
  109.   if (line[index]) /* Still something left */
  110.     strcpy(line, &line[index]);
  111.   else
  112.     line[0] = 0;
  113.  
  114.   *Value = value; 
  115.   return(token);
  116. }
  117.